package peer.player2;

import java.awt.LayoutManager;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;

public class Menus extends JPanel {
	private static final long serialVersionUID = 1L;
	static JMenuBar menuBar = new JMenuBar();
	static JMenu historyMenu=new JMenu();
	
	static ArrayList<String> lstHistory=new ArrayList<String>();
	Object[][] fileMenu={
			{"�ļ�(F)",new Character('F')},
			{"�����ϴβ���",new Character('J')},
			{"���ļ�",new Character('O')},
			{"��URL",new Character('U')}
	};
	static Object[][] lastFileMenu={
			{"��ʷ��¼(L)",new Character('L')},
			{"��ռ�¼",new Character('D')}
	};
	Object[][] LookMenu={
			{"�鿴",new Character('C')},
			{"�����б�",new Character('P')},
			{"ԭʼ��С",new Character('S')},
			{"ȫ��",new Character('Q')},
			{"��ǰ��",new Character('T')}
	};
	Object[][] optionMenu={
			{"ѡ��",new Character('O')},
			{"��j��ʽ",new Character('F')},
			{"P2P����",new Character('A')},
			{"ʹ�������ļ���",new Character('X')},
			{"����8",new Character('B')}
	};
	private void CreateFileMenu()
	{
		JMenu menu=new JMenu();
		menu.setText(fileMenu[0][0].toString());
		menu.setMnemonic(((Character)fileMenu[0][1]).charValue());
		
		JMenuItem item=new JMenuItem();
		item.setText((String)fileMenu[1][0]);//�����ϴβ���
		item.setMnemonic(((Character)fileMenu[1][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		
		item=new JMenuItem();
		item.setText((String)fileMenu[2][0]);//���ļ�
		item.setMnemonic(((Character)fileMenu[2][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     Player.openFileDialog();
					}

				}
		);
		menu.add(item);
		item=new JMenuItem();
		item.setText((String)fileMenu[3][0]);
		item.setMnemonic(((Character)fileMenu[3][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
						openUrl();
					}

				}
		);
		menu.add(item);
		menuBar.add(menu);
	}
	static void openUrl()
	{
		String strVal=JOptionPane.showInputDialog(null, "������URL");
		if(strVal==null)
			return;
		if(!strVal.startsWith("http://"))
		{
			strVal="http://"+strVal;
		}
		if(strVal.indexOf(".")==-1)
		{
			JOptionPane.showMessageDialog(null,"��ʽ����ȷ�������²���!");
			return;
		}
	     Player.listModel.clear();
	     Player.listModel.addElement(strVal);
	     Player.setVideoFile(strVal);
	     Player.isPlayOne = true;
	}
	private void CreateHistoryMenu()
	{
		historyMenu.setText((String)lastFileMenu[0][0]);
		historyMenu.setMnemonic(((Character)lastFileMenu[0][1]).charValue());
		menuBar.add(historyMenu);
		JMenuItem item=new JMenuItem();
		item.setText((String)lastFileMenu[1][0]);
		item.setMnemonic(((Character)lastFileMenu[1][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		historyMenu.add(item);
	}
	
	static void AddPlayRecord(String name)
	{
		JMenuItem item=new JMenuItem();
		item.setText(name);
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		historyMenu.add(item);
	}
	
	private void CreateLookMenu()
	{
		JMenu menu=new JMenu();
		menu.setText(LookMenu[0][0].toString());
		menu.setMnemonic(((Character)LookMenu[0][1]).charValue());
		
		JMenuItem item=new JMenuItem();
		item.setText((String)LookMenu[1][0]);
		item.setMnemonic(((Character)LookMenu[1][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		item=new JMenuItem();
		item.setText((String)LookMenu[2][0]);
		item.setMnemonic(((Character)LookMenu[2][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		item=new JMenuItem();
		item.setText((String)LookMenu[3][0]);
		item.setMnemonic(((Character)LookMenu[3][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		item=new JMenuItem();
		item.setText((String)LookMenu[4][0]);
		item.setMnemonic(((Character)LookMenu[4][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		menuBar.add(menu);
		JMenu subMenu=new JMenu();
		subMenu.setText("�����л�");
		JRadioButtonMenuItem closeItem=new JRadioButtonMenuItem("�ر�");
		JRadioButtonMenuItem item1=new JRadioButtonMenuItem("����1");
		JRadioButtonMenuItem item2=new JRadioButtonMenuItem("����2");
		JRadioButtonMenuItem item3=new JRadioButtonMenuItem("����3");
		item1.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
						JOptionPane.showMessageDialog(null,"aa");
					}
				}
		);
		ButtonGroup group=new ButtonGroup();
		group.add(closeItem);
		group.add(item1);
		group.add(item2);
		group.add(item3);
		subMenu.add(closeItem);
		subMenu.add(item1);
		subMenu.add(item2);
		subMenu.add(item3);
		menu.add(subMenu);
	}
	
	private void CreateOptionMenu()
	{
		JMenu menu=new JMenu();
		menu.setText(optionMenu[0][0].toString());
		menu.setMnemonic(((Character)optionMenu[0][1]).charValue());
		
		JCheckBoxMenuItem item=new JCheckBoxMenuItem();
		item.setText((String)optionMenu[1][0]);
		item.setMnemonic(((Character)optionMenu[1][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		
		item=new JCheckBoxMenuItem();
		item.setText((String)optionMenu[2][0]);
		item.setMnemonic(((Character)optionMenu[2][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		item=new JCheckBoxMenuItem();
		item.setText((String)optionMenu[3][0]);
		item.setMnemonic(((Character)optionMenu[3][1]).charValue());
		item.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
					     
					}

				}
		);
		menu.add(item);
		
		final JCheckBoxMenuItem baritem=new JCheckBoxMenuItem();
		baritem.setText((String)optionMenu[4][0]);
		baritem.setMnemonic(((Character)optionMenu[4][1]).charValue());
		baritem.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent e) 
					{
						
					     //if(baritem.getState())
					     //{
						//Player.pane.setVisible(false);
					    Player.frame.getContentPane().remove(Player.toolBar_1);
					    	//Player.frame.setVisible(true);
					    // }
					}

				}
		);
		menu.add(baritem);
		menuBar.add(menu);
	}
	public Menus() {
		// TODO Auto-generated constructor stub
		CreateFileMenu();
		CreateHistoryMenu();
		CreateLookMenu();
		CreateOptionMenu();
		Player.frame.setJMenuBar(menuBar);
	}

	

}
